package com.badger.spring.cloud.alibaba.sentinel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.badger.spring.cloud.alibaba.sentinel.api.DemoFeignApi;

/**
 * @EnableDiscoveryClient 开启服务注册和发现
 * @EnableFeignClients 开启feign的客户端
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class SentinelOpenFeignApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SentinelOpenFeignApplication.class, args);
    }

    @RestController
    public class DemoController {
        @Autowired
        DemoFeignApi api;

        @GetMapping("/feign/demo")
        @SentinelResource(value = "demo")
        public String demo() {
            return api.demo();
        }
    }
}
